<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<%@ taglib uri="/WEB-INF/tlds/att.tld" prefix="att"%>

<html>

<head>
<meta name="decorator" content="moduleEdit" />
<script type="text/javascript">
$(document).ready(function() {
	$("#supplierBankForm").validate({
		submitHandler: function(form){
			Oosp_Loading('正在提交，请稍等...');
			form.submit();
		},
		errorContainer: "#messageBox",
		errorPlacement: function(error, element) {
			$("#messageBox").text("输入有误，请先更正。");
			if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
				error.appendTo(element.parent().parent());
			} else {
				error.insertAfter(element);
			}
		}
		
	});
});
	$(function() {
		//找到联系人目前最大行
		max_tr_contact = $("#hidden_bank").closest("table").find("tr").length - 2;

	})

	//添加隐藏域
	function add_hidden(tId, tList) {
		var tr = $(tId).clone();
		var table = $(tId).closest("table");
		//替换所有的hidden，方便spring的form绑定
		var inputs = tr.find("input");
		if (tId == "#hidden_bank") {
			max_tr_contact++;
		}
		inputs.each(function() {
			if (tId == "#hidden_bank") {
				this.id = tList + max_tr_contact + this.id;
				this.name = tList + "[" + max_tr_contact + "]" + this.name;
			}

		});
		tr.show();
		table.append(tr);
	}
	function delete_tr(t, dList) {
		var tr = $(t).closest("tr");
		var id = tr.find("input :first").val();
		if (id != 0) {
			var val = $(dList).val();
			if (val == "") {
				$(dList).val(id);
			} else {
				$(dList).val(val + "," + id);
			}
		}
		tr.remove();

	}

</script>
</head>
<body>
<div class="Report_f">
           <div class="Report_f_1">
                <div class="Report_f_title_1">品牌准入</div>
                <ul class="nav nav-tabs Report_f_title_2">
                    <li><a href="#label_1" data-toggle="tab">银行信息</a></li>
                  </ul>
			<!-- Tab panes -->
			<div class="tab-content Report_f_title_3">
                  <div class="tab-pane active" id="label_1">
                         <div class="Report_f_title_4">
					<form:form id="supplierBankForm" modelAttribute="supplierBank" action="${contextPath}/biz/brand/supplierBank/save" method="post" class="form-inline" role="form">
						<form:hidden path="id" />
						<tags:message content="${message}" />
						<table class="table table-striped table-hover o-l-table table-bordered" id="table1">
							<thead class="t_1">
								<tr>
									<th>银行代码</th>
									<th>开户银行名称</th>
									<th>开户银行简称</th>
									<th>开户账号</th>
									<th>
										<button onclick="add_hidden('#hidden_bank','supplierBankList');"
										type="button" class="btn btn-warning btn_1 pull-right">添&nbsp;加</button>
									</th>
								</tr>
							</thead>
							<tbody>
								<c:forEach items="${supplierBank.supplierBankList}"
									varStatus="var">
									<tr>
										<form:hidden path="supplierBankList[${var.index}].id"/>
										<form:hidden path="supplierBankList[${var.index}].supplierId"/>
											<td>
												<form:input id="supplierBankList[${var.index}].bankCode"
													path="supplierBankList[${var.index}].bankCode" maxlength="200"
													class="f_5 required" />
											</td>
											<td>
												<form:input id="supplierBankList[${var.index}].bankName"
													path="supplierBankList[${var.index}].bankName" maxlength="200"
													class="f_5 required" />
											</td>
											<td>
												<form:input id="supplierBankList[${var.index}].bankSname"
													path="supplierBankList[${var.index}].bankSname"
													maxlength="200" class="f_5 required" />
										   </td>
											<td>
												<form:input id="supplierBankList[${var.index}].bankNo"
												path="supplierBankList[${var.index}].bankNo" maxlength="200"
												class="f_5 required" />
										</td>	
										<td><input type="button"
											onclick="delete_tr(this,'#delBankIds')" value="删除"
											class="btn btn-default btn-sm"></td>
									</tr>
								</c:forEach>
								<!-- 隐藏行，用于新增明细start -->
								<tr style="display: none" id="hidden_bank">
									<input type="hidden" maxlength="20" value="0" name=".id" id=".id">
									<input type="hidden" maxlength="20"
										value="${supplierBank.supplierId}" name=".supplierId" id=".supplierId">
										<td>
											<input type="text" maxlength="20" value=""
												class="f_5 required" name=".bankCode" id=".bankCode">
										 </td>
										<td>
											<input type="text" maxlength="20" value=""
												class="f_5 required" name=".bankName" id=".bankName">
										 </td>
											<td>
												<input type="text" maxlength="20" value=""
													class="f_5 required" name=".bankSname" id=".bankSname">
											 </td>
											<td>
											<input type="text" maxlength="20" value=""
												class="f_5 required" name=".bankNo" id=".bankNo">
										</td>	
									<td><input type="button"
										onclick="delete_tr(this,'#delBankIds')" value="删除"
										class="btn btn-default btn-sm"></td>
								</tr>
								<!-- 隐藏行，用于新增明细end -->
							</tbody>
					</table>
					<input type="hidden" name="delBankIds" id="delBankIds">
				   <div class="f_12">
				     <button type="submit" id="save" class="btn btn-success btn_5 btn_right" <c:if test="${supplierBank.supplierId == null}">disabled="disabled"</c:if>>保&nbsp;存</button>
				   </div>
  		   </form:form>
                 </div>
              </div>
		  </div>
	</div>	
</div>
</body>
</html>